
/****************************************************************************/
/*Copyright (c) 2011, Florent DEVILLE.                                      */
/*All rights reserved.                                                      */
/*                                                                          */
/*Redistribution and use in source and binary forms, with or without        */
/*modification, are permitted provided that the following conditions        */
/*are met:                                                                  */
/*                                                                          */
/* - Redistributions of source code must retain the above copyright         */
/*notice, this list of conditions and the following disclaimer.             */
/* - Redistributions in binary form must reproduce the above                */
/*copyright notice, this list of conditions and the following               */
/*disclaimer in the documentation and/or other materials provided           */
/*with the distribution.                                                    */
/* - The names of its contributors cannot be used to endorse or promote     */
/*products derived from this software without specific prior written        */
/*permission.                                                               */
/* - The source code cannot be used for commercial purposes without         */ 
/*its contributors' permission.                                             */
/*                                                                          */
/*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       */
/*"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT         */
/*LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS         */
/*FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE            */
/*COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,       */
/*INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,      */
/*BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;          */
/*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER          */
/*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT        */
/*LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN         */
/*ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE           */
/*POSSIBILITY OF SUCH DAMAGE.                                               */
/****************************************************************************/

#pragma once

#include "CVector3f.h"
#include "CMatrix.h"

//store the primitive name
#include <string>
using std::string;

//type of movable
#include "MovableType.h"

//This class represent a 3D object which can be move in the scene
class Movable
{
public:
	//flag which indicate if the object is currently selected
	bool _selected;

	//flags which indicate which mark axis is currently hoovered
	CVector3f _hoover;

	//translation to apply to the geometry
	CVector3f _translate;

	//rotation to apply to the geometry
	CVector3f _rotate;

	//scale to apply to the geometry
	CVector3f _scale;

	//translation to apply to the translation mark
	CVector3f _translateMark;

	//radius of the rotation marks
	float _rotationMarkRadius;

	//name of the primitive
	string _name;

	//offset to display the marks
	float _translateMarkOffset;

	//the type of movable object
	MOVABLETYPE _movableType;

public:
	//constructor
	Movable();

	//destructor
	virtual ~Movable();

	//set the selected flag
	void setSelected(bool selected);

	//return the selected flag
	bool getSelected() const;

	//toggle the selected flag
	void toggleSelected();

	//set the hoover flags
	void setHoover(unsigned int x, unsigned int y, unsigned int z);

	//set the hoover flags
	void setHoover(const CVector3f& h);

	//pre render function
	virtual void preRender();

	//render the object
	virtual void Render() = 0;

	//post render function
	virtual void postRender();

	//draw the geometry
	void draw();

	//draw the translation mark of the object
	virtual void drawTranslationMark();

	//draw the rotation mark of the object
	virtual void drawRotationMark();

	//draw the scale mark of the object
	virtual void drawScaleMark();

	//test if the point v is on the mark of the primitive
	//out indicate which axis is hoovered
	virtual bool isTranslationMark(const CVector3f& v);

	//test if the point v is on the rotation mark of the primitive
	//hoover indicate which axis is hoovered
	virtual bool isRotationMark(const CVector3f& v);

	//test if the point v is on the scale mark of the primitive
	//hoover indicate which axis is hoovered
	virtual bool isScaleMark(const CVector3f& v);

	//determine if the point v is a point of the geometry object
	virtual bool isGeometry(const CVector3f& v) const = 0;

	//get the translation vector
	CVector3f getTranslate()const;

	//get the rotation angles
	CVector3f getRotate()const;

	//get the rotation matrix of the movable object
	virtual CMatrix getRotationMatrix()const;

	//get the scaling factor
	CVector3f getScale()const;
	
	//get the movable type
	MOVABLETYPE getMovableType()const;

	//set the translation vector
	virtual void setTranslate(const CVector3f& t);

	//set the rotation angles
	virtual void setRotation(const CVector3f& r);

	//set the scaling factors
	virtual void setScale(const CVector3f& s);

	//translate the object's position by the vector
	virtual void translate(const CVector3f& t);

	//rotate the objects using the vector
	virtual void rotate(const CVector3f& r);

	//add the vector as scale components
	virtual void scale(const CVector3f& s);

};